﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Productions;
using MangoMes.Commont.Domain.ProductionWorking;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.Pickinges
{
    public class PickingStatusBackHandler : IRequestHandler<PickingStatusBackCommand, ResultsDTO>
    {
        #region 仓储
        private readonly IBateRepository<Picking> PickingRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pickingRepository"></param>
        public PickingStatusBackHandler(IBateRepository<Picking> pickingRepository)
        {
            PickingRepository = pickingRepository;
        }
        #endregion

        #region 领料审批
        /// <summary>
        /// 领料审批
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ResultsDTO> Handle(PickingStatusBackCommand request, CancellationToken cancellationToken)
        {
            var list = new ResultsDTO() { Code = 0 };
            DapperHelper dapper = new DapperHelper();
            var conn = dapper.MangoMesWrite;

            var picking = new Picking();

            var str = "update picking set PickingStatus='" + request.PickingStatus + "' where PickingId='" + request.PickingId + "'";

            var res = PickingRepository.GetAll(str, picking, conn);
            if (res != null)
            {
                list.Code = 1;
                list.Message = "修改成功";
            }
            return list;
        }
        #endregion

    }
}
